package com.h.heal.mapper;

import com.h.heal.entity.Video;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface VideoMapper {
    @Select("SELECT * FROM `video`")
    List<Video> findAll();

    @Select("SELECT * FROM `video` where video_vname=#{video_vname}")
    List<Video> findByvideo_vname(String video_vname);

    @Select("SELECT * FROM `video` where video_uid=#{video_uid}")
    List<Video> findByvideo_uid(String video_uid);


    @Delete("delete from `video` where video_vid =#{video_vid}")
    void deleteById(int id);


//    List<Video> findBySearch(String video_vname, String video_uid);


    @Insert("INSERT INTO `heal`.`video` (`video_uid`, `video_vname`, `video_timestamp`, `video_vv`, `video_like`, `video_url`, `video_img`) VALUES (#{video_uid}, #{video_vname}, #{video_timestamp}, 0, 0, #{video_url},#{video_img})")
    void create(Video video);

    @Select("SELECT * FROM `video` where video_vid=#{video_vid}")
   Video findById(int id);

    @Update("update video set video_vname=#{video_vname},video_url=#{video_url},video_img=#{video_img} where video_vid=#{video_vid}")
    void edit(Video video);

    @Update("UPDATE video SET video_like=video_like+1 WHERE video_vid =#{video_vid}")
    void like(@Param("video_vid")String video_vid);


    @Update("UPDATE video SET video_vv=video_vv+1 WHERE video_vid =#{video_vid}")
    void vv(@Param("video_vid")String video_vid);

    List<Video> findBySearch(String video_vname, String video_uid);


    int count(String video_vname, String video_uid);

    //分页查找
    List<Video> findBySearchWithPage(String video_vname, String video_uid, int startPageIndex, int pageSize);



//    INSERT INTO `heal`.`video` (`video_vid`, `video_uid`, `video_vname`, `video_timestamp`, `video_vv`, `video_like`, `video_url`) VALUES (30001, 1000012, '第一个视频', '2022-08-05 21:30:08', 4321, 43, 'https://www.bilibili.com/video/BV1j4411W7F7')
}
